local qitian = fk.CreateSkill {

  name = "joy__qitian",

  tags = { Skill.Wake, },

}



qitian:addEffect(fk.GameStart, {
  name = "joy__qitian",
  frequency = Skill.Wake,
  events = {fk.GameStart,fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return  player:hasSkill(qitian.name) and
      player:usedSkillTimes(qitian.name, Player.HistoryGame) == 0 and player.hp == 1
    else
      return  target == player and player:hasSkill(qitian.name) and
      player:usedSkillTimes(qitian.name, Player.HistoryGame) == 0 and player.hp == 1
    end
  end,
  can_wake = function(self, event, target, player, data)
    return player.hp == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player,-1)
    if not player.dead then
      room:handleAddLoseSkills(player,"joy__huoyan|joy__jindouyun")
    end
  end,
})
qitian:addEffect(fk.HpChanged, {
  name = "joy__qitian",
  frequency = Skill.Wake,
  events = {fk.GameStart,fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return  player:hasSkill(qitian.name) and
      player:usedSkillTimes(qitian.name, Player.HistoryGame) == 0 and player.hp == 1
    else
      return  target == player and player:hasSkill(qitian.name) and
      player:usedSkillTimes(qitian.name, Player.HistoryGame) == 0 and player.hp == 1
    end
  end,
  can_wake = function(self, event, target, player, data)
    return player.hp == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player,-1)
    if not player.dead then
      room:handleAddLoseSkills(player,"joy__huoyan|joy__jindouyun")
    end
  end,
})

return qitian